package cn.kgc.filter;


import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @ClassName LoginFilter
 * @Description TODO
 * @Author yaozhaobao
 * @Date 2020/11/13 18:17
 * @Version 1.0
 **/
@WebFilter(urlPatterns = {"/sys/*"})
public class LoginFilter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response =  (HttpServletResponse) servletResponse;
        if(request.getSession().getAttribute("LOGIN_KEY") == null){
            response.setContentType("text/html;charset=utf-8");
            PrintWriter out = response.getWriter();
            out.write("未登录");
        }else{
            filterChain.doFilter(servletRequest,servletResponse);
        }
    }
}
